package org.fengling.readingplatform.pay.controller;

import com.alipay.api.AlipayApiException;
import org.fengling.readingplatform.model.vo.common.Result;
import org.fengling.readingplatform.model.vo.common.ResultCodeEnum;
import org.fengling.readingplatform.pay.factory.PaymentFactory;
import org.fengling.readingplatform.pay.template.AbstractPaymentHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/api/pay/")
public class PayController {

    //下单,支付
    @GetMapping("submitPay/{orderNo}")
    @ResponseBody
    public Result submitPay(@PathVariable(value = "orderNo") String orderNo,
                            String strategy) throws AlipayApiException {
        String form = null;

        strategy = "Alipay";

        AbstractPaymentHandler invokeStrategy = PaymentFactory.getInvokeStrategy(strategy);

        form = invokeStrategy.getPayment(orderNo);

        return Result.build(form, ResultCodeEnum.SUCCESS);
    }
}
